﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace kxjsj
{
    public partial class readFile : Form
    {
        public readFile()
        {
            InitializeComponent();
        }

        private void readFile_Load(object sender, EventArgs e)
        {
            if(Directory .Exists (System .Windows .Forms .Application .StartupPath +"\\评审材料\\"+Tag.ToString ()))
            {
            TreeNode rootnode = new TreeNode(System .Windows .Forms .Application .StartupPath +"\\评审材料\\"+Tag.ToString ());
            treeView1.Nodes.Add(rootnode);
            FillChildNodes(rootnode);
            treeView1.Nodes[0].Expand();
            }
            else
            {
                MessageBox.Show ("材料未生成或者丢失，请重新生成。","提示");
                this.Dispose();
            }
        }

        private void FillChildNodes(TreeNode node)
        {
            try
            {
                DirectoryInfo dirs = new DirectoryInfo(node.FullPath);
                foreach (FileInfo dir in dirs.GetFiles())
                {
                    TreeNode newnode = new TreeNode(dir.Name);
                    node.Nodes.Add(newnode);
                    //newnode.Nodes.Add("*");
                }       
                foreach (DirectoryInfo dir in dirs.GetDirectories())
                {
                    TreeNode newnode = new TreeNode(dir.Name);
                    node.Nodes.Add(newnode);
                    newnode.Nodes.Add("*");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void treeView1_BeforeExpand_1(object sender, TreeViewCancelEventArgs e)
        {
            if (e.Node.Nodes[0].Text == "*")
            {
                e.Node.Nodes.Clear();
                FillChildNodes(e.Node);
            }
        }

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if(e.Node.Nodes.Count ==0)
                System.Diagnostics.Process.Start(e.Node .FullPath );
        }
    }
}
